package com.github.postsanf.yinian.adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.github.postsanf.yinian.R;

/**
 * Created by Administrator on 2016/9/26.
 */
public class TimeMarksColorAdapter extends BaseAdapter{

    private Context context;
    private String[] color;
    public TimeMarksColorAdapter(Context context,String[] color){
        this.context=context;
        this.color=color;
    }
    @Override
    public int getCount() {
        return color.length;
    }

    @Override
    public Object getItem(int position) {
        return color[position];
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (convertView==null){
            convertView=View.inflate(context, R.layout.color_item,null);
            viewHolder = new ViewHolder();
            viewHolder.iv_color= ((ImageView) convertView.findViewById(R.id.iv_color));
            convertView.setTag(viewHolder);
        }else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        viewHolder.iv_color.setBackgroundColor(Color.parseColor(color[position]));

        viewHolder.iv_color.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (listener!=null){
                    listener.onColorListClickListener(color[position]);
                }
            }
        });
        return convertView;
    }

    public class ViewHolder{
        ImageView iv_color;
    }

    private OnColorListClickListener listener;
    public interface OnColorListClickListener{
        void onColorListClickListener(String colors);
    }

    public void setOnColorListClickListener(OnColorListClickListener listener){
        this.listener=listener;
    }
}
